﻿using System;
using System.Net.Sockets;
using SailHero.Soft.ESB.Communication.ClientAndServer.Communication;
using SailHero.Soft.ESB.Communication.ClientAndServer.Communication.EndPoints;
using SailHero.Soft.ESB.Communication.ClientAndServer.Communication.Messages;
using SailHero.Soft.ESB.Communication.ClientAndServer.Communication.Messengers;

namespace SailHero.Soft.ESB.Communication.ClientAndServer.Server
{
    /// <summary>
    /// Represents a client from a perspective of a server.
    /// </summary>
    public interface IServerClient : IMessenger
    {
        /// <summary>
        /// This event is raised when client disconnected from server.
        /// </summary>
        event EventHandler Disconnected;

        /// <summary>
        /// This event is raised when a new Client login after Connect without any error.
        /// It does not guaranties that message is properly handled and processed by remote application.
        /// </summary>
        event EventHandler<MessageEventArgs> ClientLogin;

        /// <summary>
        /// Unique identifier for this client in server.
        /// </summary>
        string ClientId { get; }

        /// <summary>
        /// 客户端的唯一编号
        /// </summary>
        string MN { get; set; }

        /// <summary>
        /// 客户端的唯一编号
        /// </summary>
        string PW { get; set; }
        /// <summary>
        /// 超时重发的次数，按212协议标准来说，每隔15分钟一次登录，
        /// 2次之后还没登录成功，则复位通讯模块，即在服务端强制关闭Socket链接
        /// </summary>
        int DefautltReSendTimes { get; set; }
        /// <summary>
        /// 考虑可能212协议默认15分钟时间过长的问题
        /// 增加新的链路联通性测试包频率计数器
        /// </summary>
        int ReSendTimes { get; set; }
        //Does not define any additional member

        ///<summary>
        /// Gets endpoint of remote application.
        ///</summary>
        ESBEndPoint RemoteEndPoint { get; }

        /// <summary>
        /// Gets the current communication state.
        /// </summary>
        CommunicationStates CommunicationState { get; }


        Socket ClientSocket { get; }

        /// <summary>
        /// 停止所有链路联通性测试
        /// </summary>
        void StopPing(int h);

        /// <summary>
        /// Disconnects from server.
        /// </summary>
        void Disconnect();

        /// <summary>
        /// 登录超时时间，以分钟为单位，
        /// 按照协议需要两次来完成，
        /// 例如：30分钟超时，就需要每隔15分钟进行一次登录，、
        /// 超过2次视为超时
        /// </summary>
        int LoginTimeOut { set; get; }


    }
}
